package hanjia;

import suanfa.ListNode;

import java.util.HashSet;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/5-下午3:55
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode22 {

    public ListNode detectCycle(ListNode head) {
            if (head==null||head.next==null){
                return null;
            }

        HashSet<ListNode> set = new HashSet<>();
        while (set.add(head)){

            head=head.next;
            if (head==null){
                break;
            }
        }
        return head;

    }
}
